At 15:49 +0200 on 13/10/98, Andy Lewis wrote:
> You wouldn't want to share your backup and restore scripts would you?
Well, they are not that brilliant. Their main merit is that the names of
all the tables and sequences are gathered together at the top of the file
so it's easy to add and drop tables and sequences, or adapt the script to
another database. The tables are dumped to separate files, named
<tablename>.dmp, located in the current working directory.
Run the script with the name of the database as command-line argument.
Backup:
=======
#!/bin/csh
#
set tables=(auth cat_link categories clct_cat collections links priv
session session_reserve)
set seqs=(category_no clct_no link_no sess_no)
#
if ( $#argv != 1 ) then
echo "usage: $0 dbname"
exit 1
endif
#
# dump tables
#
foreach table ( $tables )
echo "Now dumping table: $table"
pg_dump -f $table.dmp -a -t $table $1
end
#
# dump sequences
#
foreach seq ( $seqs )
echo "Now dumping sequence: $seq"
echo "DROP SEQUENCE $seq;" > $seq.dmp
pg_dump -a -t $seq $1 | sed '/\\connect/d' >> $seq.dmp
end
Restore:
========
#!/bin/csh
#
set tables=(auth cat_link categories clct_cat collections links priv
session session_reserve)
set seqs=(category_no clct_no link_no sess_no)
#
if ( $#argv != 1 ) then
echo "usage: $0 dbname"
exit 1
endif
#
# restore tables
#
foreach table ( $tables )
echo "Now restoring $table"
psql $1 < $table.dmp
end
#
# restore sequences
#
foreach seq ( $seqs )
echo "Now restoring sequence $seq"
psql $1 < $seq.dmp ;
end
(Sorry, the first shell languague I learned is csh, so that's what I use).
Herouth
--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma